from sqlalchemy.orm import relationship

from .base import BaseModel
from .user import User
from sqlalchemy import Column, Integer, String, ForeignKey


class Course(BaseModel):

    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(512), nullable=False,
                  unique=False, comment='课程名称')  # 用来搜索
    img = Column(String(512), nullable=True, comment='课程封面')  # 用来搜索
    # o_path = Column(String(512), nullable=False,
    #                 unique=True, comment='vs生成对象的磁盘路径')
    output_dir = Column(String(512), comment="处理后的输出存储目录，释放资源可用到")
    user_id = Column(Integer, ForeignKey(User.id),
                     nullable=False, comment='导入课程的用户的ID')
    chapters = relationship('Chapter', backref='course',
                            lazy=True)
